/***************************************************************************
 *   Copyright (C) 2007 by saa   *
 *   root@saa   *
 ***************************************************************************/

#include <QThread>
#include <QRegExp>

#include "routeserver.h"


class TracerouteResultParser : public QThread
{
    Q_OBJECT
    public:
        TracerouteResultParser (QObject * parent = 0);
        void run();
        void setStringForParsing(const QString & _tracerouteResult) {m_tracerouteResult = _tracerouteResult;}
        
    public slots:
        void parseTracerouteResult(const QString &tracerouteResult);
        
    signals:
        void parsingFinished(QList<tracerouteNode> tracerouteNode);
        void logParserMessage(const QString & message, const LogFlag::LogLevels = LogFlag::Parser) const;

    private:
        QString checkTTL();
        QString checkIP();
        QString checkASN();
        QStringList checkTripTime();
        QString checkMPLS();
        void cutString(const int index, const QRegExp & pattern);
        void log(const QString & message, const LogFlag::LogLevels = LogFlag::Parser) const;
        
        QString m_tracerouteResult;
        QString string;

        QRegExp ipPattern; // search for ip
        QRegExp twoDigitNumberParrern; //  search for route number
        QRegExp asnPattern; // search for ASN
        QRegExp fiveDigitNumberPattern; 
        QRegExp timePattern;// search for trip time
        QRegExp taciturnHostPattern;
        QRegExp mplsPattern;
};
